package main

func main() {
	isMatch("abc", "ab*")
}

const (
	one = '.'
	all = '*'
)

func isMatch(s string, p string) bool {
	m, n := len(s)+1, len(p)+1
	dp := make([][]bool, m)
	for i := range dp {
		dp[i] = make([]bool, n)
	}
	dp[0][0] = true
	for i := 1; i < m; i++ {
		for j := 1; j < n; j++ {
			if s[i] == p[j] || p[j] == '.' {
				dp[i][j] = dp[i-1][j-1]
			} else if p[j] == '*' {
				if p[j-1] == s[i] || p[j-1] == '.' {
					dp[i][j] = dp[i-2][j] || dp[i][j-2]
				} else {
					dp[i][j] = dp[i][j-2]
				}
			} else {
				dp[i][j] = false
			}
		}
	}
	return dp[m][n]
}
